package cn.acmoj.oj.service;

import cn.acmoj.oj.bean.Problem;
import cn.acmoj.oj.dao.IProblemDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * cn.acmoj.oj.service
 * Springer
 * 2017-12-25
 */

@Service
public class ProblemService {

    @Resource
    private IProblemDao dao;

    public Problem get(int pid, String admin) {
        Map<String, Object> param = new HashMap<>();
        param.put("problem_id", pid);
        param.put("start", 0);
        if (!admin.isEmpty()) {
            param.put("defunct", admin);
        }
        param.put("num", 1);
        try {
            return dao.selectByParam(param).get(0);
        } catch (NullPointerException e) {
            e.printStackTrace();
            return null;
        }
    }

}
